package com.example.task1.ui.AllService.movies;

import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.example.task1.R;
import com.example.task1.bean.WordBean;
import com.example.task1.ui.AllService.word.MoviesAdapter;
import com.google.android.material.tabs.TabLayout;

import java.util.Arrays;
import java.util.List;

public class MoviesFilmActivity extends AppCompatActivity {

    private TabLayout tabLayout;
    private ViewPager pager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_film_movies);
        ActionBar supportActionBar = getSupportActionBar();
        supportActionBar.setTitle("影片");
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        initView();
        List<WordBean> list = Arrays.asList(new WordBean("推荐", new MoviesFilmFragment())
                , new WordBean("预告", new MoviesFilmPreviewFragment()));
        MoviesAdapter moviesAdapter = new MoviesAdapter(getSupportFragmentManager(),list);
        pager.setAdapter(moviesAdapter);
        tabLayout.setupWithViewPager(pager);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    private void initView() {
        tabLayout = (TabLayout) findViewById(R.id.tab_layout);
        pager = (ViewPager) findViewById(R.id.pager);
    }
}